package com.lebang.controller.buss;

import com.lebang.domain.DownloadPkgDetail;
import com.lebang.model.Whether;
import com.lebang.service.DownAppService;
import com.lebangweb.response.Callback;
import com.lebangweb.response.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.time.LocalDateTime;

/**
 * 每日必赚管理后台
 *
 * @Author: hwq
 * @Date: 2020/1/2 16:43
 * @Version 1.0
 */
@Controller
@RequestMapping("/sys/pkgdetail")
public class PkgDetailController {
    @Autowired
    private DownAppService baseService;
    @GetMapping("/list")
    public String list() {
        return "/pkgdetail/list";
    }

    @GetMapping("/add")
    public String add(Long id, Model model) {
        DownloadPkgDetail vo;
        if (id != null) {
            vo = baseService.selectById(id);
        } else {
            vo = new DownloadPkgDetail();

        }
        model.addAttribute("item", vo);
        return "/pkgdetail/add";
    }

    @PostMapping("/edit")
    @ResponseBody
    public JsonData edit(DownloadPkgDetail sort) {
        if (sort.getId() != null) {
            sort.setModifyTime(LocalDateTime.now());
            baseService.updateById(sort);
        } else {
            sort.setOpenLock(Whether.NO.getDbIndex());
            sort.setCreateTime(LocalDateTime.now());
            sort.setHasDeleted(Whether.NO.getDbIndex());
            baseService.insertModel(sort);
        }
        return Callback.success("success", "修改成功");
    }

}
